function CheckAll(form,obj){
	var checkBox = form.houses;
	if(checkBox.value){
		obj.checked ? checkBox.checked = true : checkBox.checked = false;
	}else{
		for (var i = 0; i < checkBox.length; i++) {	
			obj.checked ? checkBox[i].checked = true : checkBox[i].checked = false;
		}
	}
}

function deleteHouses(form,sendUrl){
	houses = getHouses(form);
	if (houses == false || houses=='') {
		return false;
	}
	sendUrl = sendUrl+'a=delete&houses='+houses;

	showDialog('confirm','确定要删除选中的房源?',0,function(){
		ajax.send(sendUrl,'',ajax.get);
	});
}


function deleteHouse(houseid,sendUrl) {
	houseid = houseid - 0;
	if (!houseid) {
		showDialog('error',"数据有误");
	}
	sendUrl = sendUrl+'a=delete&houses='+houseid;
	showDialog('confirm','确定要删除选中的房源?',0,function(){
		ajax.send(sendUrl,'',ajax.get);
	});
}

function exceptHouse(form,sendUrl) {
	houses = getHouses(form);
	if (houses == false || houses=='') {
		return false;
	}
	sendUrl = sendUrl+'a=except&houses='+houses;
	ajax.send(sendUrl,'',function(){
		var rText = ajax.request.responseText.split('\t');
		if (typeof(rText[1]) != 'undefined' && in_array(rText[1],['hire','sale'])) {
			showDialog('',rText[0],2);
			setTimeout("window.location.href='"+rText[2]+"';",2000);
		}
	});
}


function upHouse(form,sendUrl) {
	houses = getHouses(form);
	if (houses == false || houses=='') {
		return false;
	}
	sendUrl = sendUrl+'a=uphouse&houses='+houses;
	ajax.send(sendUrl,'',ajax.get);
}

function refreshHouse(sendUrl,houseid) {
	sendUrl = sendUrl+'a=refresh&houseid='+houseid;
	ajax.send(sendUrl,'',ajax.get);
}

function getHouses(form) {
	var checkBoxObj = form.houses;
	var houses = '';
	if(checkBoxObj == 'undefined' || checkBoxObj == null){
		showDialog('error',"请至少选择一个房源");
		return false;
	}
	for (var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if (e.name != "" && e.type == 'checkbox' && e.checked && isNumeric(e.value)) {
			houses += houses == '' ? e.value : ',' + e.value;
		}
	}
	if("" == houses || houses == "undefined" || houses == null ){
		showDialog('error',"请至少选择一个房源");
		return false;
	}
	return houses;
}

function isNumeric(p) {
	if (p * 1 == p) {
	   return true;
	}
	return false;
}

function housePermit() {
	var url = "index.php?m=house&q=manage&a=ajax&part=permit";
	ajax.send(url,'abc=abc',function(){
		ajax.get();
	});
}

function agree(){
	var item = getObj('item');
	item.checked = true;
	closep();
}

function editUpload(){
	var ajaxtable = getObj('ajaxtable');
	if(ajaxtable){
		var length = ajaxtable.childNodes.length;
		for(var i = 0;i<length;i++){
			var td = ajaxtable.childNodes[i].childNodes[11];
			td.style.display = "none";
		}
	}
}

function getPlateByAreaId(areaid,id,checkplate){
	var url = 'index.php?m=house&q=manage&a=ajax&part=subplate&id='+areaid+'&checkplate='+checkplate;
	var plate = getObj(id);
	ajax.send(url,'',function(){
		var responseText =  ajax.request.responseText;
		if(responseText == 0){
			plate.style.display = 'none';
		}else{
			plate.style.display = '';
			plate.innerHTML = ajax.request.responseText;
		}
	});
}

